package com.ycu.jk16.mall.controller.admin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ycu.jk16.mall.service.OrderService;
import com.ycu.jk16.mall.service.ProductService;
import com.ycu.jk16.mall.service.UserService;
import com.ycu.jk16.mall.util.common.ResponseJsonUtils;

@Controller
@RequestMapping("/manage/statistic")
public class StatisticsController {
	
	@Autowired
	@Qualifier("userService")
	private UserService userService;
	
	@Autowired
	@Qualifier("productService")
	private ProductService productService;
	
	@Autowired
	@Qualifier("orderService")
	private OrderService orderService;
	
	@RequestMapping("/base_count")
	public void baseCount(HttpServletResponse response) {
		Map<String,Object> statisticData = new HashMap<String,Object>();
		Map<String,Object> info = new HashMap<String,Object>();
		try {
			
			Integer userCount = userService.countUser();
			Integer productCount = productService.countProduct(); // 产品数量
			Integer orderCount = orderService.countOrder(); // 订单数量
			
			info.put("userCount", userCount);
			info.put("productCount", productCount); // 产品数量
			info.put("orderCount", orderCount);   // 订单数量
			
			statisticData.put("status", 0);
			statisticData.put("data", info);
		} catch(Exception e) {
			e.printStackTrace();
			statisticData.put("status", 1);
			statisticData.put("msg", "出错了");
		} finally {
			ResponseJsonUtils.json(response, statisticData);
		}
	}
}
